// grunt 入口文件
const sass = require('sass')
const loadGruntTasks = require('load-grunt-tasks')

module.exports = grunt => {
  grunt.initConfig({
    sass: {
      options: {
        sourceMap: true,// 生成soureMap文件
        implementation: sass
      },
      main: {
        files: {
          'dist/main.css': 'src/main.scss'
        }
      }
    },// sass插件配置
    babel: {
      options: {
        presets: ['@babel/presets-env']
      },
      main: {
        files: {
          'dist/app.js': 'src/app.js'
        }
      }
    },// 转换ES6+
    watch: {
      js: {
        files: ['src/*.js'],
        tasks: ['babel']
      },
      css: {
        files: ['src/*.scss'],
        tasks: ['sass']
      }
    }
  })

  // grunt.loadNpmTasks('grunt-sass') // 单独加载删除插件

  loadGruntTasks(grunt)// 自动加载任务所需的grunt插件

  grunt.registerTask('default', ['sass', 'babel', 'watch'])
}